/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import model.ChucVu;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import util.HibernateUtil;

/**
 *
 * @author MRDO
 */
public class ChucVuDao {
    private static Session session;
    
    public ChucVuDao(){
        SessionFactory factory = HibernateUtil.getSessionFactory();
        this.session = factory.getCurrentSession();
    }
    
    /*
     * insertChucVu
     */
    public boolean insertChucVu(String maChucVu, String chucVu){
        try {
            session.beginTransaction();
            
            ChucVu ten = new ChucVu(maChucVu, chucVu);
            
            session.save(ten);
            session.flush();
            session.getTransaction().commit();
            return true;
        } catch (Exception e) {
            if (session.getTransaction().isActive()) {
                session.getTransaction().rollback();
            }
        }
        return false;
    }
    
    /*
     * updateChucVu
     */
    public boolean updateChucVu(String maChucVu,String chucVu){
        try {
            session.beginTransaction();
            
            ChucVu ten = (ChucVu) session.get(ChucVu.class, maChucVu);
            ten.setChucVu(chucVu);
            
            session.update(ten);
            session.flush();
            session.getTransaction().commit();
            return true;
        } catch (Exception e) {
            if (session.getTransaction().isActive()) {
                session.getTransaction().rollback();
            }
        }
        return false;
    }
    
    /*
     * deleteChucVu
     */
    public boolean deleteChucVu(String maChucVu){
        try {
            session.beginTransaction();
            
            ChucVu ten = (ChucVu) session.get(ChucVu.class, maChucVu);
            
            session.delete(ten);
            session.flush();
            session.getTransaction().commit();
            return true;
        } catch (Exception e) {
            if (session.getTransaction().isActive()) {
                session.getTransaction().rollback();
            }
        }
        return false;
    }
}
